#include "videoMasker.h"


//--------------------------------------------------------------
void videoMasker::setup(int width, int height){
	grayPixels = new unsigned char[width * height];
	grayCam.allocate(width,height);
	grayCamSmooth.allocate(width,height);
	grayThin.allocate(width,height);
	grayMask.allocate(width,height);
}

//--------------------------------------------------------------
void videoMasker::process(ofCvColorImage input){

	int nPixels = input.width * input.height;
	unsigned char * pixels = input.getPixels();
	for (int i = 0; i < nPixels; i++){
		grayPixels[i] = pixels[i*3+1];
	}
	grayCam.setFromPixels(grayPixels, input.width, input.height);
	grayThin = grayCam;
	grayThin *= 2.0;
	grayCam.threshold(30);
	grayThin.erode_3x3();
	grayThin.blur();
	grayThin *= 0.66;
	grayCam.erode_3x3();
	grayCam.dilate_3x3();
	grayCam.erode_3x3();
	grayCam.erode_3x3();
	grayCam.blur();
	grayCam.blur();
	grayCam += grayThin;
	grayCam *= 0.5f;
	grayCamSmooth *= 0.5f;
	grayCamSmooth += grayCam;
	grayMask = grayCamSmooth;

}


void videoMasker::draw(float x, float y, float w, float h){
	grayMask.draw(x,y,w,h);
}
		


